package br.com.strings_serializacao;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Objetivo: Demonstrar classes de entrada e saida encadeadas.
 * Na criacao do FileWriter ou adiciono throws IOException a interface publica
 * do metodo main ou encapsulo em um bloco try/cath para tratar a excecao.
 * @author Sidney
 *
 */
public class ExemploBufferedWriter {
	public static void main(String[] args) {
		File f = new File("c://Buffered.txt");
		try{
			//construtor de FileWriter com objeto File
			FileWriter fw = new FileWriter(f);
			//construtor de BufferedWriter com objeto FileWriter
			BufferedWriter bw = new BufferedWriter(fw);
			bw.write("Teste BufferedWriter");
			bw.newLine();//este metodo separa as linhas, se nao for chamado os caracteres
			//serao inseridos na mesma linha
			bw.write("Escrevendo em outra linha");
			bw.flush();
			bw.close();
			
			//construtor FileReader com objeto File
			FileReader fr = new FileReader(f);
			//construtor BufferedReader com objeto Reader
			BufferedReader br = new BufferedReader(fr);
			while(br.read()!= -1 ){
				System.out.println(br.readLine());
			}
		}catch(IOException e){}
	}
}
